package it.polimi.digitalstate.entities;

import it.polimi.digitalstate.dto.ElectionDTO;

import java.io.Serializable;
import java.lang.String;
import java.sql.Date;
import java.util.Calendar;

import javax.persistence.*;

/**
 * Entity implementation class for Entity: Election
 *
 */
@Entity
@NamedQueries(value = { 
		@NamedQuery(name = "election_getByID", query = "select e from Election e where e.id = :id" ),
		@NamedQuery(name = "election_getCandidacy", query = "select e from Election e where e.candidacystartdate <= :todaydate and e.candidacyenddate >= :todaydate"),
		@NamedQuery(name = "election_getElection", query = "select e from Election e where e.electionstartdate <= :todaydate and e.electionenddate >= :todaydate"),
		@NamedQuery(name = "election_getElectionWeak", query = "select e from Election e where e.candidacystartdate <= :todaydate and e.electionenddate >= :todaydate"),
		@NamedQuery(name = "election_getOverlappingElection", query = "select e from Election e where e.candidacyenddate >= :earliestdate or e.electionenddate >= :earliestdate"),

})
public class Election implements Serializable , IEntity {
	
	//TODO @Mohamed. Here's missing a reference to the governor who created this election. is specified in the Design
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;   
	@Column(nullable=false, unique=true)
	private String name;
	@JoinColumn(nullable=false)
	private User governor;
	@Column(nullable = false)
	private Date candidacystartdate;
	@Column(nullable = false)
	private Date candidacyenddate;
	@Column(nullable = false)
	private Date electionstartdate;
	@Column(nullable = false)
	private Date electionenddate;
	
	private static final long serialVersionUID = 1L;

	public Election() {
		super();
	}   
	public Election(String name, User governor, Date candidacystartdate, Date candidacyenddate, Date electionstartdate, Date electionenddate){
		super();
		this.name=name;
		this.governor = governor;
		this.candidacystartdate = candidacystartdate;
		this.candidacyenddate = candidacyenddate;
		this.electionstartdate = electionstartdate;
		this.electionenddate = electionenddate;
		
	}
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}   
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}   
	
	public User getGovernor() {
		return this.governor;
	}

	public void setGovernor(User governor) {
		this.governor = governor;
	}  
   
	public Date getCandidacystartdate() {
		return this.candidacystartdate;
	}

	public void setCandidacystartdate(Date Candidacystartdate) {
		this.candidacystartdate = Candidacystartdate;
	}   
	
	public Date getCandidacyenddate() {
		return this.candidacyenddate;
	}

	public void setCandidacyenddate(Date Candidacyenddate) {
		this.candidacyenddate = Candidacyenddate;
	}   
	public Date getElectionstartdate() {
		return this.electionstartdate;
	}

	public void setElectionstartdate(Date Electionstartdate) {
		this.electionstartdate = Electionstartdate;
	}   
	public Date getElectionenddate() {
		return this.electionenddate;
	}

	public void setElectionenddate(Date Electionenddate) {
		this.electionenddate = Electionenddate;
	}   
	public ElectionDTO getDTO(){
		return new ElectionDTO(id, governor.getDTO() , name, candidacystartdate, candidacyenddate, electionstartdate, electionenddate);
	}
   
}
